/* hayes.h */

/********************/
/* HAYES-INTERFACE  */
/* for Secure Phone */
/* (C) 2003 by NAH6 */
/********************/

#ifndef __HAYES_H
#define __HAYES_H
#ifdef __cplusplus
extern "C" {
#endif

/*------------*/
/*  INCLUDES  */
/*------------*/

#include "winsio.h"

/*-----------*/
/*  DEFINES  */
/*-----------*/

#define E_HAYES_NULLPTR        (-0x5101)
#define E_HAYES_CFG_MDMTYPE    (-0x5102)
#define E_HAYES_PAR_LINKSERV   (-0x5103)
#define E_HAYES_PAR_LINKCARR   (-0x5104)
#define E_HAYES_PAR_LINKPROT   (-0x5105)
#define E_HAYES_PUT_NOECHO     (-0x5106)
#define E_HAYES_PUT_ERRECHO    (-0x5107)
#define E_HAYES_PUT_BADECHO    (-0x5108)
#define E_HAYES_GET_NOREPLY    (-0x5109)
#define E_HAYES_GET_NOCHAR     (-0x510A)
#define E_HAYES_GET_ERRDATA    (-0x510B)
#define E_HAYES_EVT_RINGING    (-0x510C)
#define E_HAYES_MDM_OK         (-0x510D)
#define E_HAYES_MDM_RESPONSE   (-0x510E)
#define E_HAYES_MDM_ERROR      (-0x510F)
#define E_HAYES_MDM_CMEERR     (-0x5110)
#define E_HAYES_MDM_CMSERR     (-0x5111)
#define E_HAYES_MDM_CONNECT    (-0x5112)
#define E_HAYES_MDM_CARRIER    (-0x5113)
#define E_HAYES_MDM_DIALTONE   (-0x5114)
#define E_HAYES_MDM_LINEERR    (-0x5115)
#define E_HAYES_MDM_BUSY       (-0x5116)
#define E_HAYES_MDM_ANSWER     (-0x5117)
#define E_HAYES_MDM_VOICE      (-0x5118)
#define E_HAYES_MDM_DELAYED    (-0x5119)
#define E_HAYES_MDM_BLACKLIST  (-0x511A)

/*====*/

#define K_HAYES_INITSTRBUFLEN       (54)
#define K_HAYES_DIALPFXBUFLEN       (10)
#define K_HAYES_DIALNUMBUFLEN       (64)
#define K_HAYES_TEXTBUFLINES         (2)
#define K_HAYES_TEXTBUFWIDTH      (2048)
#define K_HAYES_ERRORTXTLEN        (128)
#define K_HAYES_CLIPBUFLEN          (64)
#define K_HAYES_INFOLEN_MAN         (64)
#define K_HAYES_INFOLEN_DEV         (96)
#define K_HAYES_INFOLEN_REV         (96)
#define K_HAYES_INFOLEN_SER         (32)
#define K_HAYES_INFOLEN_PMAN        (64)
#define K_HAYES_INFOLEN_PDEV        (96)
#define K_HAYES_INFOLEN_PREV        (96)
#define K_HAYES_INFOLEN_PSER        (32)
#define K_HAYES_INFOLEN_IMSI        (32)
#define K_HAYES_INFOLEN_SIMNR       (32)
#define K_HAYES_NETLIST_LINES       (16)
#define K_HAYES_NETLIST_WIDTH       (32)

#define K_HAYES_DELAY_ECHO         (200)
#define K_HAYES_DELAY_ESCAPE1      (200)
#define K_HAYES_DELAY_ESCAPE2     (1500)
#define K_HAYES_DELAY_ESCAPE3     (1500)
#define K_HAYES_DELAY_ESCAPE4      (500)
#define K_HAYES_DELAY_HWRING      (1500)

#define K_HAYES_TIMEOUT_RESET        (4)
#define K_HAYES_TIMEOUT_COMMAND      (2)
#define K_HAYES_TIMEOUT_DIALIN     (120)
#define K_HAYES_TIMEOUT_DIALOUT    (120)
#define K_HAYES_TIMEOUT_HANGUP       (7)
#define K_HAYES_TIMEOUT_NETLIST    (120)

#define K_HAYES_POLLRATE_PWR       (120)
#define K_HAYES_POLLRATE_SIM       (600)
#define K_HAYES_POLLRATE_NET       (120)
#define K_HAYES_POLLRATE_SIG        (30)
#define K_HAYES_POLLRATE_NLIST    (1200)
#define K_HAYES_POLLRATE_SMS       (120)

/*----*/

#define K_HAYES_MODEMTYPES              (8)
#define K_HAYES_MODEMTYPE_POTS          (0)
#define K_HAYES_MODEMTYPE_POTS_GAL      (1)
#define K_HAYES_MODEMTYPE_POTS_CIR      (2)
#define K_HAYES_MODEMTYPE_POTS_ELS      (3)
#define K_HAYES_MODEMTYPE_POTS_USR      (4)
#define K_HAYES_MODEMTYPE_GSM           (5)
#define K_HAYES_MODEMTYPE_GSM_NOK       (6)
#define K_HAYES_MODEMTYPE_GSM_SIE       (7)

#define K_HAYES_LINKSERVICES            (3)
#define K_HAYES_LINKSERVICE_DATA        (0)
#define K_HAYES_LINKSERVICE_FAX         (1)
#define K_HAYES_LINKSERVICE_VOICE       (2)
#define K_HAYES_LINKSERVICE_UNKNOWN  (0xFF)

#define K_HAYES_LINKCARRIERS            (2)
#define K_HAYES_LINKCARRIER_DIG_V110    (0)
#define K_HAYES_LINKCARRIER_ANA_V32     (1)
#define K_HAYES_LINKCARRIER_UNKNOWN  (0xFF)

#define K_HAYES_LINKPROTOCOLS           (3)
#define K_HAYES_LINKPROTOCOL_RAW        (0)
#define K_HAYES_LINKPROTOCOL_REL        (1)
#define K_HAYES_LINKPROTOCOL_RELCOMP    (2)
#define K_HAYES_LINKPROTOCOL_UNKNOWN (0xFF)

/*----*/

#define K_HAYES_CALLSTATE_IDLE       (0)
#define K_HAYES_CALLSTATE_CONNECTING (1)
#define K_HAYES_CALLSTATE_CONNECTED  (2)
#define K_HAYES_CALLSTATE_ESCAPED    (3)

#define K_HAYES_REPLY_OK             (0)
#define K_HAYES_REPLY_UNKNOWN        (1)
#define K_HAYES_REPLY_ERROR          (2)
#define K_HAYES_REPLY_CMEERR         (3)
#define K_HAYES_REPLY_CMSERR         (4)
#define K_HAYES_REPLY_CONNECT        (5)
#define K_HAYES_REPLY_CARRIER        (6)
#define K_HAYES_REPLY_DIALTONE       (7)
#define K_HAYES_REPLY_LINEERR        (8)
#define K_HAYES_REPLY_BUSY           (9)
#define K_HAYES_REPLY_ANSWER        (10)
#define K_HAYES_REPLY_VOICE         (11)
#define K_HAYES_REPLY_DELAYED       (12)
#define K_HAYES_REPLY_BLACKLIST     (13)

#define K_HAYES_EVENT_CEER           (1)
#define K_HAYES_EVENT_RIBACK         (2)
#define K_HAYES_EVENT_RING           (3)
#define K_HAYES_EVENT_CRING          (4)
#define K_HAYES_EVENT_CIDDATE        (5)
#define K_HAYES_EVENT_CIDTIME        (6)
#define K_HAYES_EVENT_CIDNMBR        (7)
#define K_HAYES_EVENT_CIDNAME        (8)
#define K_HAYES_EVENT_CIDMESG        (9)
#define K_HAYES_EVENT_CLIP          (10)
#define K_HAYES_EVENT_CARRIER       (11)
#define K_HAYES_EVENT_CR            (12)
#define K_HAYES_EVENT_DR            (13)
#define K_HAYES_EVENT_CBC           (14)
#define K_HAYES_EVENT_SCKS          (15)
#define K_HAYES_EVENT_SCID          (16)
#define K_HAYES_EVENT_CREG          (17)
#define K_HAYES_EVENT_COPS          (18)
#define K_HAYES_EVENT_CSQ           (19)
#define K_HAYES_EVENT_CBM           (20)
#define K_HAYES_EVENT_CMT           (21)
#define K_HAYES_EVENT_CMTI          (22)
#define K_HAYES_EVENT_CDS           (23)
#define K_HAYES_EVENT_SMGO          (24)
#define K_HAYES_EVENT_CSCA          (25)
#define K_HAYES_EVENT_CPMS          (26)
#define K_HAYES_EVENT_CMGL          (27)
#define K_HAYES_EVENT_CMGR          (28)
#define K_HAYES_EVENT_CMGW          (29)
#define K_HAYES_EVENT_CMGC          (30)
#define K_HAYES_EVENT_CMGS          (31)
#define K_HAYES_EVENT_CMSS          (32)
#define K_HAYES_EVENT_CPBS          (33)
#define K_HAYES_EVENT_CPBR          (34)

#define K_HAYES_REPORTCR_A           (0)
#define K_HAYES_REPORTCR_S           (1)
#define K_HAYES_REPORTCR_RA          (2)
#define K_HAYES_REPORTCR_RS          (3)
#define K_HAYES_REPORTCR_F           (4)
#define K_HAYES_REPORTCR_VA          (5)
#define K_HAYES_REPORTCR_VS          (6)
#define K_HAYES_REPORTCR_VRA         (7)
#define K_HAYES_REPORTCR_VRS         (8)
#define K_HAYES_REPORTCR_V           (9)
#define K_HAYES_REPORTCR_AVA        (10)
#define K_HAYES_REPORTCR_AVS        (11)
#define K_HAYES_REPORTCR_AVRA       (12)
#define K_HAYES_REPORTCR_AVRS       (13)
#define K_HAYES_REPORTCR_AVF        (14)
#define K_HAYES_REPORTCR_AAV        (15)
#define K_HAYES_REPORTCR_ASV        (16)
#define K_HAYES_REPORTCR_ARAV       (17)
#define K_HAYES_REPORTCR_ARSV       (18)
#define K_HAYES_REPORTCR_AFV        (19)
#define K_HAYES_REPORTCR_GPRS       (20)

#define K_HAYES_REPORTDR_NONE        (0)
#define K_HAYES_REPORTDR_V42         (1)

/*--------------*/
/*  STRUCTURES  */
/*--------------*/

struct hayes_config
{
  volatile unsigned char *sigterm;
  unsigned char sio_portnum;
  unsigned char sio_obxport;
  unsigned char sio_rilport;
  unsigned char sio_baudrate;
  unsigned char sio_flowctrl;
  unsigned char sio_usedtr;
  unsigned char sio_usedsr;
  unsigned char sio_usedcd;
  unsigned char sio_usering;
  unsigned char modem_type;
  unsigned char modem_pots_volume;
  unsigned char modem_pots_tonedial;
  unsigned char modem_pots_dialtone;
  unsigned char modem_pots_busytone;
  unsigned char modem_initstr[K_HAYES_INITSTRBUFLEN];
  unsigned char modem_dialpfx[K_HAYES_DIALPFXBUFLEN];
};

struct hayes_data
{
  struct hayes_config cfg;
  struct sio_data     sio;
  unsigned char  callstate;
  unsigned short textposx;
  unsigned char  textposy;
  unsigned char  textlines;
  unsigned short ptmr_pwr;
  unsigned short ptmr_sim;
  unsigned short ptmr_net;
  unsigned short ptmr_sig;
  unsigned short ptmr_nlist;
  unsigned short ptmr_sms;
  unsigned short error_cme;
  unsigned short error_cms;
  unsigned char  error_txt;
  unsigned char  error_txtbuf[K_HAYES_ERRORTXTLEN];
  unsigned char  ring_event;
  unsigned char  ring_clip;
  unsigned char  ring_clipfmt;
  unsigned char  ring_clipbuf[K_HAYES_CLIPBUFLEN];
  unsigned char  link_serv;
  unsigned char  link_prot;
  unsigned long  link_rate;
  unsigned char  gsm_mainpwr;
  unsigned char  gsm_battlvl;
  unsigned char  gsm_simstat;
  unsigned char  gsm_netlogin;
  unsigned short gsm_netnum;
  unsigned short gsm_netlac;
  unsigned short gsm_netcid;
  unsigned char  gsm_rxsiglvl;
  unsigned char  gsm_rxsigqual;
  unsigned char  info_man;
  unsigned char  info_dev;
  unsigned char  info_rev;
  unsigned char  info_ser;
  unsigned char  info_pman;
  unsigned char  info_pdev;
  unsigned char  info_prev;
  unsigned char  info_pser;
  unsigned char  info_imsi;
  unsigned char  info_simnr;
  unsigned char  infobuf_man  [K_HAYES_INFOLEN_MAN];
  unsigned char  infobuf_dev  [K_HAYES_INFOLEN_DEV];
  unsigned char  infobuf_rev  [K_HAYES_INFOLEN_REV];
  unsigned char  infobuf_ser  [K_HAYES_INFOLEN_SER];
  unsigned char  infobuf_pman [K_HAYES_INFOLEN_PMAN];
  unsigned char  infobuf_pdev [K_HAYES_INFOLEN_PDEV];
  unsigned char  infobuf_prev [K_HAYES_INFOLEN_PREV];
  unsigned char  infobuf_pser [K_HAYES_INFOLEN_PSER];
  unsigned char  infobuf_imsi [K_HAYES_INFOLEN_IMSI];
  unsigned char  infobuf_simnr[K_HAYES_INFOLEN_SIMNR];
  unsigned char  netlist_state  [K_HAYES_NETLIST_LINES];
  unsigned short netlist_netnum [K_HAYES_NETLIST_LINES];
  unsigned char  netlist_namelen[K_HAYES_NETLIST_LINES];
  unsigned char  netlist_namebuf[K_HAYES_NETLIST_LINES][K_HAYES_NETLIST_WIDTH];
  unsigned char  sms_overflow;
  unsigned short textlen[K_HAYES_TEXTBUFLINES];
  unsigned char  textbuf[K_HAYES_TEXTBUFLINES][K_HAYES_TEXTBUFWIDTH];
};

/*--*/

struct hayes_link
{
  unsigned char dialout;
  unsigned char remnumlen;
  unsigned char remnumbuf[K_HAYES_DIALNUMBUFLEN];
  unsigned char service;
  unsigned char carrier;
  unsigned char protocol;
  unsigned long baudrate;
};

/*--------------*/
/*  PROTOTYPES  */
/*--------------*/

signed short hayes_open  (struct hayes_data *dseg, \
                          const struct hayes_config *cfg);
signed short hayes_close (struct hayes_data *dseg);

signed short hayes_setup   (struct hayes_data *dseg);
signed short hayes_watch   (struct hayes_data *dseg, struct hayes_link *link, \
                            unsigned char clrclip);
signed short hayes_connect (struct hayes_data *dseg, struct hayes_link *link);
signed short hayes_hangup  (struct hayes_data *dseg);

#ifdef __cplusplus
}
#endif
#endif


/*** EOF ***/
